Quantcast
Channel: Small Basic
Viewing all 669 articles
Browse latest View live

Microsoft Small Basic Guru Award Winners! - May, 2014

$
0
0

The Small Basic Guru Awards celebrate the Small Basic articles on TechNet Wiki, contributed from valued wiki authors like YOU!

Each month, the contributions are scored by a panel of judges (5 per category, 2-3 in each are MS experts), and the winners of each category are showered with love and attention from all corners of TechNet and MSDN!

See the links at the bottom, to find out more about the competition and how to enter.

 

We have picked the top three highest scored contributions for each category to bestow our awards upon. The awards are in gold, silver and bronze, the gold obviously being the top winner of the category. The last column is just a few of the comments judges made during the judging process. In some cases, we have not obtained permission to use the judges names, so they have been reduced to initials.

 

Guru Award Small Basic Technical Guru - May 2014  

Gold Award Winner

 

Philip ConrodProgramming Home Projects with Microsoft Small Basic: Chapter 1: Writing Programs Using Small BasicRZ: "Very systematic introduction."
Ed Price: "Good overview article that covers all the basics!"
Michiel Van Hoorn: "Nice introduction into the history of Basic. Needs to be updated to reflect current support for Windows version (Windows NT? LOL )"

Silver Award Winner

 

Philip ConrodProgramming Home Projects with Microsoft Small Basic: Chapter 6: Flash Card Math Quiz ProjectMichiel Van Hoorn: "This article (or book chapter) is excellent material to learn how to envision, design and build your program. The actual example program is also very usable."
Ed Price: "I love how this tutorial keeps building on itself as it goes!"

Bronze Award Winner

 

Nonki TakahashiSmall Basic: VariableRZ: "Very nice explanation of the concept of variables!"
Michiel Van Hoorn: "Clear explanation and not frills"
Ed Price: "Great article with fantastic formatting!"

Also worth a mention were the other entries this month:

 

 

If you haven't contributed an article for this month, and you have an idea for a wiki article, here's your chance! :D

 

More about the TechNet Guru Awards:

 

A huge thank you to EVERYONE who contributed an article to May's competition.

   - Ninja Ed


Small Basic - Hammer and Nails

$
0
0

One of the great things about Small Basic is that you have to be imaginative to solve problems, since there is such a small set of commands.  This makes it fun to use even when you have quite good programming skills - it is still a challenge to get it to do new things more efficiently.

There was a recent Small Basic forum question that highlighted this for me, and reminded me of the saying...

"If the only tool you have is a hammer, then everything looks like a nail"

 

In other words for programming - "if you know one way of doing something, then this may be how you try to do everything".  This is a very good lesson to be mindful of.


I had been adding and fixing some methods for a Small Basic extension, when I saw this post by jricestk (JR).

TextWindow Issues Can't Show after hiding textwindow

"I have tried this on 2 computers that are running windows8.1 and get the error that is in the image.

TextWindow.WriteLine("Here")
TextWindow.Hide()
TextWindow.Show()

Can anyone confirm that they get the same error? If I comment out the 1st line I don't get the error. This does occur with no extensions present."

A few posts later it was confirmed that it appeared to be a Small Basic bug and some-one suggested perhaps an extension could be written to create a fix for it.

It was a simple fix and I had just been working on extensions so I created a couple extension commands to handle hiding and showing the TextWindow.  Job done.


Then came a post by Jibba Jabba with simple and effective workaround without any need for extensions reminded me of the Hammer and Nail proverb.

"Hello jr

What about a simple work around?

I use this for both TW and GW, it solves any clearing of the TW and any Shapes issues for the GW."

TextWindow.WriteLine("hello, hide for 3 seconds")
Program.Delay(2000)
 
lastTop = TextWindow.Top
TextWindow.Top = Desktop.Height
Program.Delay(3000)
TextWindow.Top = lastTop

 


So all you have to do is move the TextWindow off the desktop, and return it to show it again - cool - lesson learned again.

Interview with a Small Basic Guru - Steve Todman (litdev)

$
0
0

We've interviewed litdev once here before. You can find that interview here:

LitDev, Scottish MCC & Forum Moderation Ninja (Sinclair Spectrum, Small Basic, Fortran, C++, C#)

 

But I also wanted to highlight an interview from Wiki Ninja, MCC, and T-SQL Guru, Naomi N.

 

You can see the full interview here:

Interview with Steve Todman (litdev) - many times Small Basic TechNet Guru Contributions Gold Winner

  

Here are some highlights...

Steve Todman (litdev) has won several gold medals in TecNet Guru Contributions in the Small Basic category.

LitDev's Community Stats:

  • Recognition Points: 21,582
  • Small Basic Guru Medals: 3 (source)
  • Forum Answers: 953
  • Helpful Forum Posts: 1,278
  • Total Forum Posts: 2,938
  • TechNet Wiki Articles: 11 (all very high quality)
  • Wiki Edits: 87
  • Wiki Comments: 53
  • Blog Posts (on this blog): 9
  • 4+ Star Ratings on Blog Posts: 22
LitDev's Top Small Basic Wiki Articles:

LitDev's Website:

 

What got you interested in writing TechNet Wiki articles?

The main reason was to create extended explanations for common questions made on a forum I contribute to, having been prompted by Ed Price.  This forum is for the Small Basic programming language which is a simplified language for children and others starting out programming.

I wanted to create a set of structured articles that go beyond the basics of syntax and introduce some ideas about good programming style, graphics, writing games, practical hints and tips and explanations of why some approaches may be better than others.
I can then use them as references to point forum questions to.

 

What do you do with TechNet Wiki, and how does that fit into the rest of your job?

My main use of the TechNet Wiki so far has been to write articles encouraging new programmers into the creative fun developing software through the Small Basic project.  I sometimes browse other articles; perhaps other Small Basic related articles or featured articles.

From a work perspective computer science is just a tool and I try to limit its impact - it's the physics that interests me not the IT.  But outside of work I do try to keep up-to-date and learn new things in the CS world and I am a bit of a hobbyist programmer.  MSDN and TechNet are great resources for inspiring me to have fun learning new things.

   

What are your favorite Wiki articles you’ve contributed?

I've only created 10 articles so far, but I think the one that has had the most impact was one on writing graphical games (see Small Basic: Dynamic Graphics).  Not surprisingly most young new programmers want to write slick graphically interesting games.  Small Basic makes this about as painless as it could be, and the programming basics are usually picked up very quickly.  The next hurdle is programming with a good structure for graphic intensive event driven programs (games) which I tried to cover in this and a few other articles.

 

Thank you to LitDev for leading our Small Basic Forum Moderation, hosting the monthly Small Basic Challenges, and helping out in the Small Basic Community Council!

You can find the full interview here (thanks again to Naomi N for hosting the interview):

Interview with Steve Todman (litdev) - many times Small Basic TechNet Guru Contributions Gold Winner 

 

I recommend you check out LitDev's articles! They are very valuable for learning more about Small Basic!

   - Ninja Ed 

 

 

Small Basic and Office Suite

$
0
0

Today, I'd like to talk about the relationship between Microsoft Small Basic and Microsoft Office (Excel, Word, PowerPoint).  Following articles are my samples.  If you find more attractive collaboration between Small Basic and Office, please let me know.

I used Office 2013 desktop version.  Other Office versions may have some limitation for articles here.


Excel

CSV

If you create CSV (comma separated value) file with Small Basic program, the file can be read from Excel as a spread sheet.  Following thread in Small Basic Forum shows a sample.

Small Basic Forum: Your Program Database

Extension

There is an Excel extension library created by jsakamoto.  This extension has four operations and one property to access Excel workbook directly from Small Basic program.

CodePlex: Excel Library for Small Basic


Word

Print Small Basic Code

You can copy and paste your code from Small Basic IDE to Word and then you can print the code to your printer.  I recommend to use 10 pt for the code font size in Word. 


PowerPoint

I wrote little bit about this in this blog.  To create image for your program, PowerPoint is very useful.  At first, Drawing tool in PowerPoint has an ability to save your shapes as PNG file.  Before export, that will be good to group your shapes.  And I recommend you to use zooming 160% to draw in PowerPoint so that you can get approximately the same size of image in your Small Basic program.  Following link is to my sample of PowerPoint file for Small Basic programming.

TechNet Gallery: Small Basic: Another Turtle Project: PowerPoint Presentation

VBA Shapes Object

The second reason - why PowerPoint is useful - is that there are powerful VBA (Visual Basic for Applications) methods to manipulate shapes.  I'm expecting to share pictures with shapes objects between Small Basic program and PowerPoint presentation.  Following site is a page of PowerPoint 2013 VBA reference.

Office Dev Center: Shapes.AddShape Method (PowerPoint)

LitDev's "Dynamic Graphics for Game Programming" - Small Basic Featured Article

$
0
0

This article from  is an introduction to graphical game programming using Small Basic.  It includes the basics of program design, movement, user interaction with keys and mouse, collision detection and introduces some more advanced ideas at the end.

You can read the full article here:

 

Small Basic: Dynamic Graphics

 

Table of Contents

 

Sprite Arrays - Featured Article

$
0
0

I recently wrote a TechNet Wiki article describing how to manage arrays of sprites in a game.

For the full article see http://social.technet.microsoft.com/wiki/contents/articles/24857.small-basic-sprite-arrays.aspx.

The following is an excerpt from one section...


Recycling sprites

We often want sprites to appear and disappear.  One way to do this is to recycle the sprites from a 'pool', activating and using them as required.  This can be good for example to fire bullets or missiles, when we only ever need a limited number on screen at the same time.

The example below fires missiles when the mouse is clicked.  A new spriteData property "Status" is used to flag that missiles are active or not.  Inactive missiles are hidden and they are shown while they are active on the screen.

 Missile Sprite

gw = 600
gh = 600
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.MouseDown = OnMouseDown
 
CreateSprites()
 
'Game Loop
While ("True")
  start = Clock.ElapsedMilliseconds
  
  If (mouseDown) Then
    FireMissile()
    mouseDown = "False"
  EndIf
  UpdateSprites()
  
  delay = 20 - (Clock.ElapsedMilliseconds - start)
  If (delay > 0) Then
    Program.Delay(delay)
  EndIf
EndWhile
 
Sub CreateSprites
  spriteImage = ImageList.LoadImage("http://litdev.hostoi.com/game_images/missile.png")
  'Sprite dimensions we use the half width and height
  spriteWidth = ImageList.GetWidthOfImage(spriteImage)/2
  spriteHeight = ImageList.GetHeightOfImage(spriteImage)/2
  
  numSprite = 50
  For i = 1 To numSprite
    spriteData["image"] = Shapes.AddImage(spriteImage)
    spriteData["Xpos"] = spriteWidth + Math.GetRandomNumber(gw-2*spriteWidth)
    spriteData["Ypos"] = gh-spriteHeight
    spriteData["Xvel"] = 0
    spriteData["Yvel"] = -5
    spriteData["Status"] = 0
    Shapes.HideShape(spriteData["image"])
    sprites[i] = spriteData
  EndFor
EndSub
 
Sub UpdateSprites
  For i = 1 To numSprite
    spriteData = sprites[i] 'get current sprite array
    
    If (spriteData["Status"] = 1) Then
      'Reposition sprite center
      spriteData["Xpos"] = spriteData["Xpos"] + spriteData["Xvel"]
      spriteData["Ypos"] = spriteData["Ypos"] + spriteData["Yvel"]
      
      'Move sprite center
      Shapes.Move(spriteData["image"],spriteData["Xpos"]-spriteWidth,spriteData["Ypos"]-spriteHeight)
      
      'Sprite finished with
      If (spriteData["Ypos"] < -spriteHeight) Then
        spriteData["Status"] = 0
        Shapes.HideShape(spriteData["image"])
      EndIf
      
      sprites[i] = spriteData 'save updated sprite array (it may have been modified)
    EndIf
  EndFor
EndSub
 
Sub FireMissile
  For i = 1 To numSprite
    spriteData = sprites[i] 'get current sprite array
    If (spriteData["Status"] = 0) Then
      spriteData["Status"] = 1
      Shapes.ShowShape(spriteData["image"])
      spriteData["Xpos"] = GraphicsWindow.MouseX
      spriteData["Ypos"] = gh-spriteHeight
      
      sprites[i] = spriteData 'save updated sprite array (it may have been modified)
      i = numSprite 'End loop
    EndIf
  EndFor
EndSub
 
Sub OnMouseDown
  mouseDown = "True"
EndSub

 

Small Basic - Being Part of a Game Dev Team?

$
0
0

Today, I'd like to pick up a thread from Small Basic Forum.  The title is "Being part of a game Dev team?".

This topic is raised by Zock77 with his first question:

"Anyone around interested in being part of a game Dev team? Like something that may go further than just the SB community?

Zock77 aims to go further than just the Small Basic community!  He already made some awesome games as follows.

Please join this game development team if you want.

Zock77's games:

Tankinator 0.02

This program is developed by Zock77 and Cobra355 as a team challenge.  You can download Tankinator from TechNet Gallery.  And version 0.03 is also featured in this blog.

Armored Assault LAN Game

This game was introduced in a post in Small Basic Forum.

Flappy bird

This program was created within a post in Small Basic Forum.  Program zip file can be downloaded from here.

LDPhysics Dirtbike game

This program was introduced here in Small Basic Forum.  Program zip file can be downloaded from here.  This is the third time that this program was featured in this blog.

SBJump original

This is his first game published as PGR013.  Upgraded version was created by Coding Cat and introduced in this blog as Featured Program. 

 

What else?  You can check all about Zock77 in this blog.

Would you join the Small Basic team in the TechNet Guru World Cup???

$
0
0

The World Cup is here again! Sort of.

 

We've got brains in our ball!

And YOU have been selected to play on our team!

Yes blog reader, step up and take a shot!

Slam some techie tips in the back of our nets!

No dribbling please, just lots of problem tackling.

So come on Gurus and use your head!

Show us your skills, wow us with your technique, and win the hearts of your nation (or at least our hearts)!

   

All you have to do is add an article to TechNet Wiki from your own specialist field. Something that fits into one of the categories listed on the submissions page. Copy in your own blog posts, a forum solution, a white paper, or just something you had to solve for your own day's work today.

   

Drop us some nifty knowledge, or superb snippets, and become MICROSOFT TECHNOLOGY GURU OF THE MONTH!

 

This is an official Microsoft TechNet recognition, where people such as yourselves can truly get noticed!

 

HOW TO WIN

 

1) Please copy over your Microsoft technical solutions and revelations to TechNet Wiki.

2) Add a link to it on THIS WIKI COMPETITION PAGE (so we know you've contributed)

3) Every month, we will highlight your contributions, and select a "Guru of the Month" in each technology.

 

If you win, we will sing your praises in blogs and forums, similar to the weekly contributor awards. Once "on our radar" and making your mark, you will probably be interviewed for your greatness, and maybe eventually even invited into other inner TechNet/MSDN circles!

 

Winning this award in your favoured technology will help us learn the active members in each community.

 

Feel free to ask any questions in the comments below.

 

More about TechNet Guru Awards

 

Thanks in advance! And special thanks to XAML guy for hosting this competition!

   - Ninja Ed


Why Microsoft Small Basic? Why not Scratch or Alice?

$
0
0

This was originally written up by the Small Basic creator, Vijay Raji...

"Both Scratch and Alice are great tools that help beginners learn the concepts of programming. They are doing so by enabling people to write "codeless" programs. Small Basic is taking a different approach by introducing code as a first-class concept."

 

Another great Codeless Programming Language/IDE is Microsoft's Kodu!

Kodu lets kids create games on the PC and Xbox via a simple visual programming language. It can be used to teach creativity, problem solving, and storytelling! One way to think of Kodu is that kids (starting at age 4), see it as playing a 3D videogame. So would you rather have kids learn to make games or play them? To them, it's the same kind of fun!

My four-year old daughter loves it (along with my 6 and 7 year old daughters)! When we say that 4-year-olds love to learn Kodu and 8-year-olds love to learn Small Basic, we're not talking about exceptions (like in Java or Python). Those are the standards!

 

So if you're going to teach a codeless programming language to a kid, you should ask yourself, Why? Is it because you think a programming language that focuses on coding is too challenging? Well, there's some truth to that. But Small Basic works hard to make it Simple, Social, and Fun! And so Small Basic makes code-FULL programming accessible and desirable to 8 year olds!

Now that's getting awfully close to the age that Scratch is aimed at! But Kodu manages to go even younger, all the way down to 4! And it has videogame-like 3D graphics that kids can play/program with on both their Xbox and their computer! So it's a really great tool to start on, and Small Basic is the logical choice for the next step. (Why take 8 steps, when you can get it done in 2?)

Or if your kid is (or you are) already 8 or older, it makes a ton of sense to jump directly into Small Basic, which will transition you into professional programming as quickly as possible. That's the goal. Let's learn so that we can change the world!

  

Hopefully this gives you a good picture of what we've been up to at Microsoft. The future is in the hands of the next generation!

Happy 4th of July! Here's to the future!

   - Ninja Ed

Small Basic - Colors

$
0
0

You can set colors in Small Basic in 3 ways:

  1. Using pre-defined color names (e.g. GraphicsWindow.BrushColor = "Red")
  2. Using a Hex value code (e.g. GraphicsWindows.BrushColor = "#FF0000")
  3. Setting the Red, Green, Blue components (RGB) (e.g. GraphicsWindows.BrushColor = GraphicsWindow.GetColorFromRGB(255,0,0))

All 3 above are equivalent (Red).  See that the Hex example has 3 hexadecimal values corresponding to the Red, Green and Blue components: FF(R), 00(G) and 00(B), which in decimal are 255(R), 0(G) and 0(B).  The # symbol is required and is a standard symbol that shows that the following characters are hex values.

The 'Introducing Small Basic' guide lists all the available named colors, and their corresponding hex values, here are the Red hue colors.

You can also add transparency using the hex method by adding an extra hex value for the opacity (00 fully transparent and FF fully opaque), using ARGB in place of RGB.

For example "#80FF0000" is 50% (80) transparent Red.

GraphicsWindow.DrawText(50,50,"Hello World")
GraphicsWindow.BrushColor = "#80FF0000"
ellipse = Shapes.AddEllipse(90,35)
Shapes.Move(ellipse,40,40)

HSL Example

Another way to describe a color is by HSL, which stands for Hue, Saturation, Lightness.

  • Hue is the color (from 0 to 360) which corresponds to degrees of a circle since Hue 0 is Hue 360 (Red).
  • Saturation is the color intensity (0 to 1) which is gray to bright
  • Lightness is the lightness (0 to 1) which is black to white


Hue

Saturation

Lightness

The following code converts HSL to RGB, and displays the available Hues (0 to 360) at maximum Saturation (1) and medium Lightness (0.5).

GraphicsWindow.Width = 360
GraphicsWindow.Height = 100
 
For H = 0 To 360
  S = 1
  L = 0.5
  HSL2RGB()
  GraphicsWIndow.PenColor = GraphicsWindow.GetColorFromRGB(R,G,B)
  GraphicsWindow.DrawLine(H,0,H,100)
EndFor
 
Sub HSL2RGB
  'Check Limits
  While (H < 0)
    H = H+360
  EndWhile
  While (H >= 360)
    H = H-360
  EndWhile
  S = Math.Max(0,Math.Min(1,S))
  L = Math.Max(0,Math.Min(1,L))
  
  C = (1-Math.Abs(2*L-1))*S
  H2 = H/60
  X = C*(1-Math.Abs(Math.Remainder(H2,2)-1))
  If (H2 >= 0 And H2 < 1) Then
    R = C
    G = X
    B = 0
  ElseIf (H2 >= 1 And H2 < 2) Then
    R = X
    G = C
    B = 0
  ElseIf (H2 >= 2 And H2 < 3) Then
    R = 0
    G = C
    B = X
  ElseIf (H2 >= 3 And H2 < 4) Then
    R = 0
    G = X
    B = C
  ElseIf (H2 >= 4 And H2 < 5) Then
    R = X
    G = 0
    B = C
  ElseIf (H2 >= 5 And H2 < 6) Then
    R = C
    G = 0
    B = X
  Else
    R = 0
    G = 0
    B = 0
  EndIf
  M = L-C/2
  R = 255*(R+M)
  G = 255*(G+M)
  B = 255*(B+M)
EndSub

Small Basic - Resources for Game Programming

$
0
0

Microsoft Small Basic program language is for learning programming.  If you've already understood programming, you may would like to start game programming.  Today, I'd like to introduce some resources for game programming in Small Basic.

TechNet Wiki Articles

Blog Posts

Forum Threads

Books

All these books are written by Philip Conrod and Lou Tylee.

Videos

Popular Small Basic Games

All these games can be run in web browser.  For graphics games with keyboard control, please click game screen first.

Small Basic - Random Numbers

$
0
0

Random numbers can be very useful in your Small Basic games.  They can be used to make the game play vary from one game to the next.

The Small Basic keyword to get a random number is Math.GetRandomNumber(maxNumber).  It will return a random integer between 1 and the input value maxNumber.

Here are a few ideas and tips:

Random Position and Speed

We can position sprites with random positions and velocities.

radius = 25
numSprite = 10
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
For i = 1 To numSprite
  sprite[i] = Shapes.AddEllipse(2*radius,2*radius)
  spritePosX[i] = radius+Math.GetRandomNumber(gw-2*radius)
  spritePosY[i] = radius+Math.GetRandomNumber(gh-2*radius)
  spriteVelX[i] = Math.GetRandomNumber(11)-6
  spriteVelY[i] = Math.GetRandomNumber(11)-6
EndFor
 
While "True"
  For i = 1 To numSprite
    spritePosX[i] = spritePosX[i]+spriteVelX[i]
    spritePosY[i] = spritePosY[i]+spriteVelY[i]
    If (spritePosX[i] < radius) Then
      spritePosX[i] = radius
      spriteVelX[i] = -spriteVelX[i]
    ElseIf (spritePosX[i] > gw-radius) Then
      spritePosX[i] = gw-radius
      spriteVelX[i] = -spriteVelX[i]
    EndIf
    If (spritePosY[i] < radius) Then
      spritePosY[i] = radius
      spriteVelY[i] = -spriteVelY[i]
    ElseIf (spritePosY[i] > gh-radius) Then
      spritePosY[i] = gh-radius
      spriteVelY[i] = -spriteVelY[i]
    EndIf
    Shapes.Move(sprite[i],spritePosX[i]-radius,spritePosY[i]-radius)
  EndFor
  Program.Delay(20)
EndWhile

Random Branching

We can randomly do different things in the code,  perhaps equivalent to rolling a dice.

dice = Math.GetRandomNumber(6)
If (dice = 1) Then
  TextWindow.WriteLine("Do something for a dice roll of 1")
ElseIf (dice = 2) Then
  TextWindow.WriteLine("Do something for a dice roll of 2")
ElseIf (dice = 3) Then
  TextWindow.WriteLine("Do something for a dice roll of 3")
ElseIf (dice = 4) Then
  TextWindow.WriteLine("Do something for a dice roll of 4")
ElseIf (dice = 5) Then
  TextWindow.WriteLine("Do something for a dice roll of 5")
ElseIf (dice = 6) Then
  TextWindow.WriteLine("Do something for a dice roll of 6")
EndIf

We could also only do something with a probability, say 1 in 10.

If (Math.GetRandomNumber(10) = 1) Then
  TextWindow.WriteLine("This is a 1 in 10 event!!!")
Else
  TextWindow.WriteLine("A 10% probability event didn't happen")
EndIf

Ranges and Intervals

If we want random numbers over a different range (not 1 to maxNumber) or with smaller intervals, for example 0.2, then we can use the following formula.

rand = min + Math.GetRandomNumber((max-min+1)/interval)*interval

Here is an example using this to create random numbers between -5 and 3, with intervals of 0.2.

min = -5
max = 3
interval = 0.2
 
For i = 1 To 1000
  Random()
  TextWindow.WriteLine(rand)
EndFor
 
Sub Random
  rand = min + Math.GetRandomNumber((max-min+1)/interval)*interval
EndSub

 

Small Basic Game Programming - Let's start with RPS game

$
0
0

I'm going to write about game programming in Small Basic for several weeks on this blog.  For the first time, I'd like to pick up simple text base RPS (Rock-Paper-Scissors) game.

Main loop

This code is the main loop of this game.  Lines 4-6 are one game.  And While condition is always "True", so this is endless loop to repeat games.

 1.' Rock Paper Scissors
 2.Init()
 3.While "True"
 4.  CPU()
 5.  You()
 6.  Judge()
 7.EndWhile

Initialization

Subroutine Init is to initialize for arrays.  These arrays need only one time initialization out of the main loop.  The array hand is to input numbers.  The 2-D array judge is for game judge.

 8.Sub Init
 9.  hand = "1=Rock;2=Paper;3=Scissors;"
10.  judge["Rock"] = "Rock=Draw;Paper=Win;Scissors=Lose;"
11.  judge["Paper"] = "Rock=Lose;Paper=Draw;Scissors=Win;"
12.  judge["Scissors"] = "Rock=Win;Paper=Lose;Scissors=Draw;"
13.EndSub

Random number

In game programs, we call game AI (Artificial Intelligence) for the strategic routine for CPU side.  In game AI, random number is used sometimes.  In Small Basic, Math.GetRandomNumber() operation generates a random number.  In following subroutine, a number from 1 to 3 is generated and set into a variable n. 

14.Sub CPU
15.  n = Math.GetRandomNumber(3)
16.  cpu = hand[n]
17.EndSub

Input number

Following routine is for human side.  Te make it easier, this requires only number input for your hand.  For displaying input number just after the prompt, TextWindow.Write() operation is used instead of TextWindow.WriteLine() operation.  And to ensure the input is a number, TextWindow.ReadNumber() operation is used instead of Text.Window.Read() operation.  In line 23, if n is not from 1 to 3, null text "" is set to the variable you.

18.Sub You
19.  error = "True"
20.  While error
21.    TextWindow.Write("1(Rock), 2(Paper), 3(Scissors)? ")
22.    n = TextWindow.ReadNumber()
23.    you = hand[n]
24.    If you <> "" Then
25.      error = "False"
26.    EndIf
27.  EndWhile
28.EndSub

Judge the game

Judgement is very easy.  That is just referring an array judge.

29.Sub Judge
30.  ' param you - your hand
31.  ' param cpu - CPU's hand
32.  TextWindow.WriteLine("CPU:" + cpu)
33.  TextWindow.WriteLine("You:" + you)
34.  TextWindow.WriteLine(judge[cpu][you])
35.EndSub

Whole program is published as GXP440-0.  This game has only 35 lines.  Using technique introduced here, you may create new games something like rolling dice or so.  Let's start game programming!

Introducing Small Basics Monthly Challenge Statistics.

$
0
0

Today I’d like to introduce Small Basics Monthly Challenge Statistics.

They are provided for anyone who’s interested in community traffic in the challenge forum threads. They are updateable, responsive to community demand and sourced from the metrics displayed with each thread.

The idea to report these stats originates from the community and the Challenges themselves are originally a community invention.

The Challenges are a monthly set of real world programming tasks that deliver a popular service to the community to practice coding. They’ve been sticky since their conception.

The Statistics Package

The statistics and subsequent report treats the challenges as a going concern and aspires to present a true and fair view of activity and any interesting observations.

Hopefully this format will make it easy to maintain the stats, make them accessible and open to further contribution with broader scope and analysis.

Inside The Package is:

Preview of the Report

The Report contains a brief preamble and detailed discussion of the topics as shown in the Table of Contents.

 

The community has also included some graphical illustration including these two:

  

 

 

Here’s a preview of the Concluding Thoughts published as at June 4, 2014:

Concluding Thoughts

In considering these statistics and trends effort has been made not to view or present them as a community asset but as community-determined service. 

The significant statistical observations and interpretations discussed were:

  1. 1.     The possible impact of their innovative conception. Often is the case where something novel takes off then plateaus to a more sustained level of activity.
  2. 2.     The presence of community spirit illustrated by a pattern of oscillation in the MACD graph.
  3. 3.     A recent cross-over of MA’s at least suggesting a coming sustained average and possibly a modest growth trend buoyed by community momentum.
  4. 4.     A forward estimate of current growth to a resistance level of 50 replies.
  5. 5.     Downward sloping “views” line indicating continued interest in all challenges past and present.

It’s also worth considering when projecting, any life-cycle fluctuations that could come about by factors exogenous to the community. These may include things like product innovation, competing products, marketing and goodness knows.

Projections could also be affected by endogenous changes. These may include things like reformatting the challenges, challenge content, incentives, guest posters and any other enhancement conducive to learning and participation.

Looking Ahead

Now that this new project has been setup it seems reasonable to hope for an update of the data collected and its reporting as more data is generated.

Already the community has responded to its own demand in two ways:

  1. The Projects Conception was marshalled from community questions on the relevance and future of Small Basic; and
  2. A request to include some data analysis.

So far the package is formatted in an accounting style. The case may come about where members from diverse backgrounds may contribute further analysis perhaps from scientific, mathematical and humanities fields thereby creating a blended array of observation.

To me the Challenges and their traffic reflects an appurtenance of the virtual relationship that is evolving between a corporate giant, individuals from diverse backgrounds and technologies role in optimising mankind’s way forward to better living standards in a climate of significant ecological change.

Small Basic - Promoted in Portuguese!

$
0
0

It's fantastic to see Small Basic enjoyed by the Portuguese community, so we're going to highlight two blog posts...

 

 

Sexta-Feira - Atualização Internacional da Comunidade - Artigos sobre Small Basic

From back in May, Hezequias highlighted some great Small Basic articles from Nonki...



O destaque desta semana vai para Nonki Takahashi que escreveu diversos artigos sobre Small Basic.



Site: http://www.nonkit.com/en/

 

 

Sexta-feira: Atualização Internacional da Comunidade - Artigos sobre Small Basic Parte 2

Then last Friday, Fernando followed it up with more highlights of the great Small Basic content, also highlighting Nonki's work...

O destaque desta semana vai para Nonki Takahashi e suas contribuições em Small Basic

 

Nonki mantem uma pagina sobre Small Basic com vários artigos sobre desenvolvimento de jogos.

  

 

 

So thank you to the Portuguese Wiki Ninjas and thanks to Nonki for delivering some great Small Basic content!

   - Ninja Ed


Small Basic - Triangle Challenge

$
0
0

One of this month's challenges was set by Nonki - "Draw a picture of a regular triangle".

Here are some of the solutions:

 By Athasak, QQK823

This answer was shown to not be an exact equilateral triangle by Nonki and have the side ratios below.

 Another by Athasak after some corrections, GFS579

 By Pappa Lapub, ZLD815-0

 And one by Nonki using the Turtle, RXR906

Visit all the monthly forum challenges and solutions.

Small Basic Game Programming - Text adventure

$
0
0

Once I have answered a question in Small Basic Forum by Jeffrey SWHS about Text Adventure Game.  At that time, I made a sample text adventure program.  That program (FCD758-0) is not completed.  But I will explain about the program this time.  And until the next time I'd like to refine and upgrade this text adventure.

Opening

This is the game opening.  To game control, many Goto statements are used.  And for choosing an alternative, subroutine Choose is called.  This makes the code simple.

 1.stage_0:
 2.TextWindow.Writeline("You're at a fork in the road.")
 3.TextWindow.Writeline("Which way do you go? ")
 4.choices="LEFT,RIGHT,STAY"
 5.Choose()
 6.If id = 1 Then
 7.  Goto stage_1_1
 8.ElseIf id = 2 Then
 9.  Goto stage_1_2
10.ElseIf id = 3 Then
11.  Goto stage_1_3
12.Else
13.  TextWindow.WriteLine("Invalid choise.")
14.  Goto stage_0
15.EndIf

First Stage

The first stage branches three by the selection.  There are no code for second and third selection, so these two goes to the end.

17.stage_1_1:
18.TextWindow.Writeline("Good choice, you find some money. :)")
19.TextWindow.Writeline("Have a nice day.")
20.Goto end
21.stage_1_2:
22. 
23.stage_1_3:

End of Game

This is the end of game, only writing a new line at this time.

25.end:
26.TextWindow.Writeline("")
27.' end of program

Subroutine to Choose Alternative

This subroutine returns a number (id) selected from given choices that is described as comma separated value.

29.Sub Choose
30.  ' param choices - e.g. "A,B,C"
31.  ' return id - e.g. 1 for A
32.  ' work a,c,choice,i,len,n,p,u - will be broken
33. 
34.  ' Make array of choice 
35.  len = Text.GetLength(choices)
36.  p = 1
37.  i = 0
38.  While p <= len
39.    c = Text.GetIndexOf(Text.GetSubTextToEnd(choices,p), ",")
40.    If c = 0 Then
41.      c = len + 1
42.    Else
43.      c = c + p - 1
44.    EndIf
45.    i = i + 1
46.    choice[i] = Text.GetSubText(choices, p, c - p)
47.    p = c + 1
48.  EndWhile
49.  ' Dispaly choices 
50.  n = i
51.  For i = 1 To n
52.    TextWindow.Write(choice[i])
53.    If i < n - 1 Then
54.      TextWindow.Write(" ")
55.    ElseIf i = n - 1 Then
56.      TextWindow.Write(" or ")
57.    EndIf
58.  EndFor
59.  TextWindow.WriteLine("")
60.  ' Input
61.  a = TextWindow.Read()
62.  ' Convert to upper case
63.  u = Text.ConvertToUpperCase(a)
64.  ' Search id of choces
65.  id = n
66.  While choice[id] <> u And 0 < id
67.    id = id - 1
68.  EndWhile
69.EndSub

Most significant point of this sample is using a subroutine Choice.  So main routine becomes simple.  But, there are many Goto statements.  And if we complete this game with this manner, there will be many TextWindow.WriteLine() operations and Goto statements in the code.  So, the next week I will show simpler sample.

Small Basic Guru - June Winners: LitDev, Jibba Jabba, & Nonki Takahashi!!!

$
0
0

Congrats to LitDev, Jibba Jabba, and Nonki! Great articles this month!


Guru Award Small Basic Technical Guru - June 2014  

Gold Award Winner

 

litdevSmall Basic: Sprite ArraysEd Price: "An important topic that's well described with fantastic examples! Great article!"
Michiel Van Hoorn: "Great starter for Sprite Fundamentals and how to handle them. Briljant start point for greating you 2D shooter"

Silver Award Winner

 

Jibba JabbaSmall Basic - Monthly Challenge StatisticsEd Price: "Jibba Jabba brings us astonishing insights and data about LitDev's Small Basic Monthly Challenges!"
RZ: "This is very nicely done and showed all the statistics visually"

Bronze Award Winner

 

Nonki TakahashiSmall Basic: Challenge of the MonthRZ: "This is very nicely done and organized all challenges of the month in one place"
Ed Price: "Although this is very basic, it's incredibly helpful to get all these in one list and to access all the great challenges!"
Michiel Van Hoorn: "Good explainer on fundamental structures."

Also worth a mention were the other entries for June:

  • Small Basic: List Extension by litdev
    Michiel Van Hoorn: "Nice to have move indepth into the List Extension. "
    Ed Price: "Great in-depth explanation and practical use of the List Extension!"
  • Small Basic: Subroutine by Nonki Takahashi
    RZ: "Subroutine is not an easy topic to explain. Very glad to see Nonki explained it so well."
    Michiel Van Hoorn: "Good explainer on fundamental structures."
    Ed Price: "Perfect concept for the Wiki... to explain one topic in depth! Could benefit from more high-level info about subroutines."
  • Small Basic: Condition by Nonki Takahashi
    Michiel Van Hoorn: "Good explainer on fundamental structures."
    Ed Price: "Another great topic! This one covers Conditions and is great to read!"
  • Small Basic: Label by Nonki Takahashi
    Michiel Van Hoorn: "Good explainer on fundamental structures."
    Ed Price: "Another valuable addition to help explain the components of Small Basic!"

 

See all the Guru winners here: The Microsoft TechNet Guru Awards! (June 2014)

More about the TechNet Guru Awards:

 

It's fantastic to spend time with all of you in the community!

  • Ninja Ed

 

Small Basic - Clearing Turtle Trails

$
0
0

With the current version of Small Basic, the trails left by the turtle cannot be easily cleared.  We may want to remove the trails because we are starting the turtle off again and want a clear screen or if the number of trails is very large the program will slow.

One obvious option would be to do a GraphicsWindow.Clear().  This does delete all shapes including the turtle trails, but unfortunately it also deletes the turtle itself which cannot then be restored.

There are extension methods to re-add the turtle or even change it to another image, but without an extension it appears that the turtle trails cannot be deleted.

However, there is a workaround.

The turtle trails are actually line shapes, similar to an object created with Shapes.AddLine and internally they are named "_turtleLine1", "_turtleLine2" etc.

So we can delete these with Shapes.Remove.  All we need to know is how many lines there are or just do it for a large number greater than the number of turtle lines that may have been drawn.

Here is an example:

'Create a turtle picture
Turtle.Speed = 10
For i = 1 To 600
  Turtle.Move(10)
  Turtle.Turn(i*11)
EndFor
 
'Pause then delete it
Program.Delay(1000)
For i = 1 To 1000
  Shapes.Remove("_turtleLine"+i)
EndFor

 

Finally, note that if we add more turtle trails after removing some, then the index number added to the trail name continues to be incremented by 1 and does not revert to start from 1.

Small Basic Game Programming - Separation Between Data And Procedure

$
0
0

Last week, I introduced a text adventure game.  If I expand the game story of that manner as in the program, the program will have a lot of If statements and Goto statements.   Today, I will introduce rewritten program with less If and Goto statements.  The updated version is published as FCD758-1,

Main

Main part of this program became very simple.

1.' Text Adventure 0.2
2.' Program ID FCD758-1
3.Init()
4.Game()
5.' end of program

Initialization for Scenario Data

This data is like a main program of the previous text adventure program introduced last week.  So, this data is a kind of script language.  The grammar of this scenario data is:

  • A line started with " " (space) is displayed as a text.
  • A line ended with ":" (colon)  is treated as a label targeted by jump control statements.
  • A line started with "->" is treated as a jump (like Goto) control statement.  A jump with single label is non conditional.  A jump with several labels is conditional.
  • A line other than above and has "," (comma) is displayed as options and prompts user selection.
Game scenario ends at scenario[21] (line 32).  But for testing, I added scenario[22] (line 33) to loop back to the top.
 6.Sub Init
 7.  scenario[1] = "stage_0:"
 8.  scenario[2] = " You're at a fork in the road."
 9.  scenario[3] = " Which way do you go?"
10.  scenario[4] = "LEFT,RIGHT,STAY"
11.  scenario[5] = "-> stage_1_1,stage_1_2,stage_1_3,stage_0"
12.   
13.  scenario[6] = "stage_1_1:"
14.  scenario[7] = " Good choice, you find some money. :)"
15.  scenario[8] = " Have a nice day."
16.  scenario[9] = "-> end"
17.   
18.  scenario[10] = "stage_1_2:"
19.  scenario[11] = " You're at a stairs."
20.  scenario[12] = " Which way do you go?"
21.  scenario[13] = "UP,BACK"
22.  scenario[14] = "-> stage_2,stage_0,stage_1_2"
23.   
24.  scenario[15] = "stage_1_3:"
25.  scenario[16] = " Nothing happend."
26.  scenario[17] = " "
27.  scenario[18] = "-> stage_0"
28.   
29.  scenario[19] = "stage_2:"
30.  scenario[20] = " Hard choice. But, good luck!"
31.   
32.  scenario[21] = "end:"
33.  scenario[22] = "-> stage_0"
34.  nScenario = Array.GetItemCount(scenario)
35.  pScenario = 1
36.EndSub

Parsing and Executing the Scenario

Subroutine Game parses the scenario and execute each statement.

37.Sub Game
38.  While pScenario <= nScenario
39.    line = scenario[pScenario]
40.    If Text.StartsWith(line, " ") Then
41.      TextWindow.WriteLine(Text.GetSubTextToEnd(line, 2))
42.      pScenario = pScenario + 1
43.    ElseIf Text.EndsWith(line, ":") Then
44.      pScenario = pScenario + 1
45.    ElseIf Text.StartsWith(line, "->") Then
46.      id = 1
47.      Jump()
48.    ElseIf Text.IsSubText(line, ",") Then
49.      choices = line
50.      Choose()
51.      TextWindow.WriteLine("")
52.      If id = 0 Then
53.        id = n + 1
54.      EndIf
55.      pScenario = pScenario + 1
56.      line = scenario[pScenario]
57.      Jump()
58.    Else
59.      msg = "Unknown scenario: line " + pScenario
60.      Error()
61.    EndIf
62.  EndWhile
63.EndSub

Processing for "->" Control Statement

"->" statement behaves as Goto statement if it has a single label.  But it has some labels, it behaves like ON GOTO statement in BASIC language.  If the previous line has options, label is selected as the selected option id (1, 2, ...).  If the choice is invalid then the last label is selected.

64.Sub Jump
65.  ' param id - choice
66.  ' param line
67.  ' work label - destination
68.  len = Text.GetLength(line)
69.  p = 3
70.  While p <= len And Text.GetSubText(line, p, 1) = " "
71.    p = p + 1
72.  EndWhile
73.  label = ""
74.  For i = 1 To id
75.    c = Text.GetIndexOf(Text.GetSubTextToEnd(line, p), ",")
76.    If c = 0 Then
77.      c = len - p + 2
78.    EndIf
79.    If i = id Then
80.      label = Text.GetSubText(line, p, c - 1) + ":" 
81.    Else
82.      p = p + c
83.      If len < p Then
84.        msg = "Label shortage: line " + pScenario
85.        Error()
86.      EndIf
87.    EndIf
88.  EndFor
89.  For p = 1 To nScenario
90.    If scenario[p] = label Then
91.      pScenario = p
92.      Goto break
93.    EndIf
94.  EndFor
95.  msg = "Label " + label + " not found: line " + pScenario
96.  Error()
97.  break:
98.EndSub

Displaying Error

If the scenario has error, the program is not to be continued.  So, the program displays error and stops.

 99.Sub Error
100.  TextWindow.ForegroundColor = "Red"
101.  TextWindow.WriteLine(msg)
102.  TextWindow.WriteLine("")
103.  TextWindow.ForegroundColor = "Gray"
104.  pScenario = nScenario + 1
105.EndSub

And subroutine Choice is the same as the previous text adventure program.

With small change, the scenario can be read from a text file.  By today's update, procedures become simple.  But data (scenario) becomes little complex.  Because the scenario is a kind of script, it will be needed testing and debugging. 

For this program, there is room for improvement.  But I'm going to write about text window base game program with action next week.

Have a happy programming!

Viewing all 669 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>