It Pays To Do Bad Things In Twisted Thai Movie '13: Game Of Death'

  -  
L>Thai 21 (Part 1. The Basic Game) bầu 21 (Part 1. The Basic Game)There is a well known two player trò chơi called bầu 21 that involves 21 flags. Each player can take 1-3 flags on each turn. The goal is to lớn take the last flag on your turn (and prevent the other team from getting the last flag). Interestingly, this was part of an episode of Survivor. Feel miễn phí to watch the clip to get a feel for the game.There is no randomness in this trò chơi but there is a strategy you can use lớn win.
*

We are just going lớn focus on getting the trò chơi to work on the computer lượt thích it does on a table with pieces. Hopefully you are familiar with the rules of the game và have played it a few times. That is all you really need to know at this point.We are going to lớn code up the trò chơi so that two people can play thai 21 with each other using the program. Step 0. Draw the first flagClick here to mở cửa up the code In the đứng đầu left corner, press to lớn run the code & the output will look like this:
*

Important: Create an trương mục or Sign In, then click DuplicateTo save your work you need to create an account by clicking Sign Up
in the vị trí cao nhất right corner of the screen. If you have already created an account, click "Log In" và put in your login informationA non-profit arts group called The Processing Foundation runs this site. They are nice people and they will not send you a bunch of emails for registering.Before moving on, in the đứng đầu left click click file --> Duplicate so that the code you are working with is on your account!ObjectivesIf the program can detect that something is wrong with your code it will show a red
*
next khổng lồ that objective.If the program can detect that you have completed the objective it will show a green kiểm tra mark
*
next to lớn that objective.But the program is not very smart & if it can"t tell whether you have completed the objective it will indicate a question mark lượt thích this
*
next lớn that objective.By the kết thúc of this activity your goal is to lớn have green kiểm tra marks next to all the objectives lượt thích this:
*

The directions below will help you meet all these goals. Step 1. Look at the codeThe code here is pretty short. Here is the entire program:showaxes = false;function draw() clearscreen(240,240,240); // light gray background display(); // địa chỉ cửa hàng code below khổng lồ remove flags by pressing 1,2,3 // phối the màu sắc of the flags fill(170,170,170); // dark gray stroke(0,0,0); // đen edge // Define the flags below drawFlag(100,50); // x,y // kết thúc draw() vày NOT showroom ANY CODE AFTER THIS LINE!!!There are a couple of things to cảnh báo at this point:1. The code at the very beginning before function draw() only gets run once. Right now the only code at the beginning is this:showaxes = false;Later we will địa chỉ cửa hàng variables up there lượt thích the total number of flags (which is 21 initially)2. The code within the curly brackets of function draw() gets run over and over (and over) again. This is helpful because we want the screen khổng lồ change as different things happen in the game.

Bạn đang xem: It pays to do bad things in twisted thai movie '13: game of death'

3. Anything after // is a comment. Comments are only khổng lồ help people reading the code understand what is going on.

Xem thêm: Trigger Máy Ảnh Là Gì ? Vì Sao Trigger Lại Quan Trọng Với Máy Ảnh

The computer doesn"t bởi vì anything with the comments. In the program there are comments that label what different parts of the code are doing. There are also comments that you will use later to lớn know where khổng lồ put in code.4.

Xem thêm: Ip6 Đài Loan Loại 1, 3Tr2 Cpu 8 Nhân, Chơi Game 3D Không Giật

For right now don"t worry about the part that says // địa chỉ code below to lớn remove flags by pressing 1,2,3 We will return lớn that at the end. Step 2. Think about drawFlag và the coordinate systemThere is code at the beginning of the program:showaxes = false;Change this to:showaxes = true;This will highlight the coordinate axes we are using in this program. Your program should behave lượt thích this
*

Understanding the coordinate system is very important for the next step!Note: You can change showaxes back to lớn false if you want to, or leave it set to lớn true for the entire exercise. It is up khổng lồ you! Step 3. Showroom another 20 drawFlag commandsYou probably noticed that the game is thai 21 but right now we only have one flag (which is no fun).The simplest way lớn make sure there are 21 flags is simply to showroom more references to drawFlag like this: drawFlag(100,50); drawFlag(200,50);In the code địa chỉ cửa hàng 20 more references to drawFlag so it makes a grid lượt thích the one you see at the vị trí cao nhất of this pageMake sure to showroom your drawFlag commands AFTER the display(); function but before the } that ends the draw function After you địa chỉ each drawFlag command, press lớn run the code & see where it shows up Note: It doesn"t need to lớn look exactly like the example. Just make sure there are 21 flags on screen in some sort of grid. Optional: Change the colors
RGB stands for red, green, blue. The first number in the bracket is the amount of red, the second is the amount of green, the third is the amount of blue.
Change the fill and edge (also called "stroke") màu sắc of the flags using RGB values like this: fill(0,0,255); // r,g,b stroke(255,0,0); Copy code to lớn clipboard The code above should give you flags with a red edge & a blue filled centerYou can also change the background màu sắc by modifying the values in clearscreen:clearscreen(0,255,0);The rgb values above should give you a bright green background.To pick out your own rgb màu sắc a helpful thing to vày is to lớn go to lớn google and search on "color picker" Pick whatever màu sắc you want. Have fun!Pre Step 4. Bình luận out your drawFlag commandsIn Step 4 we are going to use a coding structure called a for loop khổng lồ draw the flags using only a few lines of code.We vị not need your 21 drawFlag commands any more but don"t erase your drawFlag commands!
Instead, phản hồi them out like this in the code:// drawFlag(100,50);// drawFlag(200,50);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);// drawFlag(???,???);Or lượt thích this:/* drawFlag(100,50); drawFlag(200,50); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???); drawFlag(???,???);*/Great! Now go on to lớn Step 4.Step 4. Showroom a for loopIn Step 3 you added trăng tròn more references to lớn drawFlag in the program so that it looks like the grid of flags image at the đứng đầu of this page. You probably found that it was a fair amount of work. It would be better if we could showroom a few lines of code that would be lượt thích a shortcut to vị the same thing.Here is some code you can địa chỉ to plot four flags in a row: y = 50; for (x = 100 ; x Copy code to clipboard If you địa chỉ this lớn your code, your program should behave lượt thích this
*

Note:
Make sure you always have complete curly bracket pairs in your code. It"s easy to thua thảm a bracket!
Important:
Draw a flow chart for this for loop Step 5. Nested for loopsAt the kết thúc of Step 3 it shows four flags created using our for loop. The goal is khổng lồ draw 21 flags so that only takes us a little bit closer.We can add another layer of shortcuts by "nesting". Here is some code that is an example of what is called "nested" for loopsfor (y = 50; y ????; y += ????) for (x = 100 ; x Copy code to lớn clipboard Replace the ???? so that it draws 24 flags in a grid lượt thích it does in this example
Obviously, this is more flags that we need khổng lồ draw. We will giảm giá khuyến mãi with that in the next step.Note: There is more than one right answer khổng lồ this step!Important: Draw a flowchart for these nested for loopsStep 6. Count the number of flags so farTo only draw 21 flags, we are going khổng lồ keep track of how many flags that have been drawn by adding three lines lớn the code: Nflags_so_far = 0; for (y = 50; y Nflags_so_far += 1; } drawText("Nflags_so_far = " + Nflags_so_far,10,470);Here are the snippets of code to lớn make it easier lớn copy paste it into your code:Nflags_so_far = 0; Copy code to lớn clipboard Nflags_so_far += 1; Copy code to clipboard drawText("Nflags_so_far = " + Nflags_so_far,10,435); Copy code to clipboard Once you add this lớn your code, your program should behave lượt thích this
Step 7. Use an if statement lớn draw the right number of flagsWe can địa chỉ cửa hàng an if statement lớn our nested for loop so that we only draw a flag if the number of flags so far is less than 21.To vì this at the beginning
of the program we need to specify the total number of flags:Ntotalflags = 21; Copy code to clipboard Now we need to add an if statement khổng lồ the nested for loop lượt thích this:Ntotalflags = 21;function draw() display(); Nflags_so_far = 0; for (y = 50; y if ( ???? drawFlag(x,y); Nflags_so_far += 1; } }Replace the ???? with either Ntotalflags or Nflags_so_far so that the program only draws 21 flags as it does in this example
Note: You can phản hồi out or erase drawText("Nflags_so_far = " + Nflags_so_far,10,435); after you have checked that it gives you 21 Important: Draw a flowchart for the nested for loops & the if statementStep 8. địa chỉ a way lớn remove 1, 2 or 3 flagsWe need lớn start making this into more of a game, starting with some keyboard input. According to lớn the rules of the game, each player can take 1, 2 or 3 flags. Let"s showroom some code to lớn make that happen when you press 1, 2 or 3 on the keyboard: drawText("Press 1, 2 or 3",150,400); if ((keyIsPressed == true) && (key == 1)) Ntotalflags -= 1; if ((keyIsPressed == true) && (key == 2)) Ntotalflags -= 2; if ((keyIsPressed == true) && (key == 3)) Ntotalflags -= 3; Copy code to lớn clipboard Copy paste this code AFTER the display(); function but before the final } of the draw() function. You should find that your program behaves lượt thích thisAt this point you should have all green kiểm tra marks! Yay! Challenge: Draw a flowchart for the ENTIRE PROGRAM! You did it!Now you have a working trò chơi of thai 21! Now it"s time to play the game & analyze it